package net.lcqf.websocket.send.message;

import cn.hutool.json.JSONUtil;
import io.netty.channel.Channel;
import net.lcqf.websocket.game.RoomManager;
import net.lcqf.websocket.request.BattleRequest;
import net.lcqf.websocket.send.MessageBaseService;
import net.lcqf.websocket.send.MessageFactory;
import net.lcqf.websocket.send.RequestType;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * 战斗
 * +----------------------------------------------------------------------
 * // | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2021-2025 聊来 All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * // +----------------------------------------------------------------------
 * // | @Author: 聊来 <18970881148@qq.com>
 * // +----------------------------------------------------------------------
 * // | DateTime: 2025/3/27 16:02
 * // +----------------------------------------------------------------------
 */

@Service
public class Battle implements MessageBaseService {

    @Override
    @PostConstruct
    public void init() {
        MessageFactory.register(RequestType.BATTLE_END.getCustomOrdinal(), this);
    }


    @Override
    public Object sendMessage(Channel channel, String msg) {
        BattleRequest request = JSONUtil.toBean(msg, BattleRequest.class);

        RoomManager.removeFromRoom(request.getRoomId(), channel);

        return null;
    }
}
